from pydantic import BaseModel, Field
from datetime import date, datetime
from typing import Optional

class StudentBase(BaseModel):
    # 必填字段
    user_id: int = Field(..., description="用户ID")
    student_no: str = Field(..., description="学号", max_length=20)
    student_name: str = Field(..., description="学生姓名", max_length=50)
    gender: int = Field(..., description="性别：1-男 2-女")
    
    # 可选字段
    birth_date: Optional[date] = Field(None, description="出生日期")
    id_card: Optional[str] = Field(None, description="身份证号", max_length=20)
    phone: Optional[str] = Field(None, description="联系电话", max_length=20)
    address: Optional[str] = Field(None, description="家庭地址", max_length=200)
    parent_name: Optional[str] = Field(None, description="家长姓名", max_length=50)
    parent_phone: Optional[str] = Field(None, description="家长电话", max_length=20)
    status: int = Field(1, description="状态：0-离校 1-在校")

class StudentCreate(StudentBase):
    """创建学生时使用的模型"""
    
    class Config:
        from_attributes = True

class StudentUpdate(BaseModel):
    """更新学生时使用的模型"""
    user_id: Optional[int] = None
    student_no: Optional[str] = None
    student_name: Optional[str] = None
    gender: Optional[int] = None
    birth_date: Optional[date] = None
    id_card: Optional[str] = None
    phone: Optional[str] = None
    address: Optional[str] = None
    parent_name: Optional[str] = None
    parent_phone: Optional[str] = None
    status: Optional[int] = None
    
    class Config:
        from_attributes = True

class Student(StudentBase):
    id: int
    create_time: Optional[datetime] = Field(None, description="创建时间")
    update_time: Optional[datetime] = Field(None, description="更新时间")
    
    class Config:
        from_attributes = True